<?php
/**
 * Created by PhpStorm.
 * User: zhao
 * Date: 2019/3/18
 * Time: 11:54
 */

namespace Admin\Controller;
use Think\Controller;


class GametestController extends BaseController
{

    public function index(){
        $model = M('gametest');
        $res = $model->select();
        $this->assign('list',$res);
        $this->display();
    }


    public function add(){

        $this->display();
    }

    public function edit(){
        $id = I('id');
        if(!$id){
            $this->error('请传入ID',U('admin/gametest/index'));
        }
        $model = M('gametest');
        $res =$model->where('id='.$id)->find();
        $this->assign('info',$res);
        $this->display();
    }
    //添加
    public function addpost(){
        if(IS_POST){
            $data=$_POST;
            $data['time']=time();
            $model = M('gametest');
            $res=$model->add($data);
            if($res){
                $this->success('添加成功',U('admin/gametest/index'));
            }else{
                $this->error('添加失败',U('admin/gametest/add'));
            }

        }else{
            $this->display();
        }
    }
    //修改
    public function editpost(){
        if(IS_POST){
            $data=$_POST;
            $id=$data['id'];
            $data['uptime']=time();
            $model = M('gametest');
            //卸载id
            unset($data['id']);
            $res=$model->where('id='.$id)->save($data);
            if($res){
                $this->success('修改成功',U('admin/gametest/index'));
            }else{
                $this->error('修改失败',U('admin/gametest/index'));
            }
        }else{
            $this->display();
        }
    }
	
	
	    public function status(){
       if(IS_POST){
           $data=$_POST;
           $id=$data['id'];
           $status=$data['status'];
           $db=M('gametest');
           if($status==1){
               //开启
               unset($data['id']);
               $res=$db->where('id='.$id)->save($data);
               if($res){
                   $this->success('显示成功');
               }else{
                   $this->error('不存在！~~');
               }

           }
           if($status==0){
               //开启
               unset($data['id']);
               $res=$db->where('id='.$id)->save($data);
               if($res){
                   $this->success('隐藏成功');
               }else{
                   $this->error('不存在！~~');
               }

           }
       }
    }
	
	
	
}

?>